package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.activity.AddActivityDTO;
import com.qk.dto.activity.UpdateActivityDTO;
import com.qk.entity.Activity;
import com.qk.dto.activity.QueryPageActivityDTO;
import com.qk.management.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:gzc
 * @Date: 2025/10/06 21:09
 * @Description:
 */
@RestController
@RequestMapping("/activities")
@Slf4j
public class ActivityController {
    @Autowired
    private ActivityService activityService;


    @GetMapping
    public Result queryListByPage(QueryPageActivityDTO queryPageActivityDTO) {
        log.info("分页查询参数：{}", queryPageActivityDTO);
        PageResult<Activity> queryListByPageVO = activityService.queryListByPage(queryPageActivityDTO);
        return Result.success(queryListByPageVO);
    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id) {
        log.info("删除参数：{}", id);
        activityService.deleteById(id);
        return Result.success();
    }

    @PostMapping
    public Result addActivity(@RequestBody AddActivityDTO addActivityDTO) {
        log.info("新增参数：{}", addActivityDTO);
        activityService.addActivity(addActivityDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result queryById(@PathVariable Integer id) {
        log.info("查询参数：{}", id);
        Activity activity = activityService.queryById(id);
        return Result.success(activity);
    }

    @PutMapping
    public Result updateById(@RequestBody UpdateActivityDTO updateActivityDTO) {
        log.info("修改参数：{}", updateActivityDTO);
        activityService.updateActivity(updateActivityDTO);
        return Result.success();
    }



    @GetMapping("/type/{type}")
    public Result queryByType(@PathVariable Integer type) {
        log.info("查询参数：{}", type);
        return Result.success(activityService.queryByType(type));
    }
}
